package com.hongyuan.coach.ui.member.view_mode;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.coach.data.md5.BaseUtil;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.mvvmhabitx.bus.RxBus;
import com.hongyuan.mvvmhabitx.bus.event.SingleLiveEvent;
import com.hongyuan.mvvmhabitx.utils.ToastUtils;
import com.hongyuan.coach.base.CustomViewModel;
import com.hongyuan.coach.data.Constants;
import com.hongyuan.coach.data.MyRepository;
import com.hongyuan.coach.myview.scllor_view.UnitBean;
import com.hongyuan.coach.myview.scllor_view.UnitBeanUtils;
import com.hongyuan.coach.ui.course.beans.OsBeans;
import com.hongyuan.coach.ui.member.beans.FilterBeans;

import java.util.List;


public class MemberFilterViewModel extends CustomViewModel<MyRepository> {

    //筛选实体类
    public ObservableField<FilterBeans> filter = new ObservableField<>();

    public MemberFilterViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        //重置选项
        public SingleLiveEvent<Void> resetCheck = new SingleLiveEvent<>();
    }

    //有效会员
    public BindingCommand activeMember = new BindingCommand(() -> {
        filter.get().setType("1");
    });
    //失效会员
    public BindingCommand invalidMember = new BindingCommand(() -> {
        filter.get().setType("2");
    });
    //男
    public BindingCommand man = new BindingCommand(() -> {
        filter.get().setSex("1");
    });
    //女
    public BindingCommand woman = new BindingCommand(() -> {
        filter.get().setSex("2");
    });
    //少于3节
    public BindingCommand minThird = new BindingCommand(() -> {
        filter.get().setNum("3");
        filter.notifyChange();
    });
    //少于7节
    public BindingCommand minSeven = new BindingCommand(() -> {
        filter.get().setNum("7");
        filter.notifyChange();
    });

    //重置
    public BindingCommand reset = new BindingCommand(() -> {
        filter.get().setNum("");
        filter.get().setSex("");
        filter.get().setType("");

        uc.resetCheck.call();
    });

    //确定筛选
    public BindingCommand submit = new BindingCommand(() -> {
        RxBus.getDefault().post(filter.get());
        finish();
    });


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);


    }
}
